#pragma once
#include<bits/stdc++.h>
using namespace std;
struct Edge;
struct Node {
	int value = 0;
	int in = 0;
	int out = 0;
	vector<Node*>nexts;
	vector<Edge*>edges;
	Node(int& val) :value(val) {}
};
struct Edge {
	Node* from;
	Node* to;
	int weight;
	Edge(int wei, Node* fro, Node* t) :weight(wei), from(fro), to(t) {}
};
struct Graph {
	map<int, Node*> nodes;
	set<Edge*>edges;
};
//matrix[0][0]:from,matrix[0][1]:to,matrix[0][1]:value
Graph createGraph(vector<vector<int>>matrix) {
	Graph graph;
	for (vector<int> eg : matrix) {
		int from = eg[0];
		int to = eg[1];
		int weight = eg[2];
		if (!graph.nodes.count(from)) {
			graph.nodes[from] = new Node(from);
		}
		if (!graph.nodes.count(to))
			graph.nodes[to] = new Node(to);
		Node* fromNode = graph.nodes[from];
		Node* toNode = graph.nodes[to];
		Edge* edge = new Edge(weight, fromNode, toNode);
		graph.edges.insert(edge);
		fromNode->out++;
		toNode->in++;
		fromNode->nexts.push_back(toNode);
		fromNode->edges.push_back(edge);
	}
	return graph;
}